const JsonResult = require('@/utils/httpResponse.unit')
const { apiGetQuestionClassify, apiGetQuestionPage, apiGetQuestionDetail } = require('@/http/question')

class QuestionController {
  async getQuestionClassify (req, response) {
    try {
      const data = await apiGetQuestionClassify()
      JsonResult.success({
        req,
        data,
        response,
        message: '查询成功'
      })
    } catch (error) {
      JsonResult.fail({ req, response, error, message: '查询失败' })
    }
  }

  async getQuestionPageList (req, response) {
    try {
      const { tagId, page = 1 } = req.query
      const data = await apiGetQuestionPage(tagId, page)
      JsonResult.success({
        req,
        data,
        response,
        message: '查询成功'
      })
    } catch (error) {
      JsonResult.fail({ req, response, error, message: '查询失败' })
    }
  }

  async getQuestionDetail (req, response) {
    try {
      const { tagId, id } = req.query
      const data = await apiGetQuestionDetail(id, tagId)
      JsonResult.success({
        req,
        data,
        response,
        message: '查询成功'
      })
    } catch (error) {
      JsonResult.fail({ req, response, error, message: '查询失败' })
    }
  }
}

module.exports = new QuestionController()
